package com.framework.buss.ai.service.impl;

import com.framework.buss.ai.model.DiseaseType;
import com.framework.buss.ai.params.DiseaseTypeParam;
import com.framework.buss.ai.params.QuestionParam;
import com.framework.buss.ai.service.IAssessmentService;
import com.framework.buss.ai.service.IDiseaseTypeService;
import com.framework.buss.ai.service.IQuestionService;
import com.framework.buss.ai.vo.AssessmentVO;
import com.framework.buss.ai.vo.QuestionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author zhangzhg
 */
@Service
public class AssessmentService implements IAssessmentService {
    @Autowired
    private IDiseaseTypeService diseaseTypeService;
    @Autowired
    private IQuestionService questionService;

    /**
     * 返回快速评估配置的问题列表
     */
    @Override
    public List<AssessmentVO> list(DiseaseTypeParam param) {
        // 所有的病害类型（第三类）
        List<DiseaseType> diseaseTypeList = diseaseTypeService.list(param);
        QuestionParam param1 = new QuestionParam();
        param1.setBridgeType(param.getBridgeType());
        param1.setCategory(param.getCategory());
        // 第三类下的所有问题
        List<QuestionVO> questionList = questionService.list(param1);
        Map<String, List<QuestionVO>> map = questionList.stream().collect(Collectors.groupingBy(QuestionVO::getDiseaseType));

        // 组装成返回对象
        List<AssessmentVO> list = new ArrayList<>();
        diseaseTypeList.forEach(it -> {
            AssessmentVO vo = new AssessmentVO();
            vo.setDiseaseType(it);
            List<QuestionVO> questionItemList = map.get(it.getType());
            vo.setQuestionList(questionItemList);
            list.add(vo);
        });
        return list;
    }
}
